package controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import dao.BusinessDao;
import dao.BusinessTypeDao;
import dto.IndexDto;
import model.Business;
import model.BusinessType;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
@WebServlet("/BusinessListController")
public class BusinessListController extends HttpServlet{
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public BusinessListController() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
      int  id= Integer.parseInt(request.getParameter("id"));
//        System.out.println(id);

        BusinessDao bd = new BusinessDao();
//        BusinessTypeDao btd = new BusinessTypeDao();
        List<Business> bs = bd.findAllBusinessById(id);
//        List<BusinessType> bst = btd.findAllTypes();
        for(Business  t:bs){
            System.out.println(t.getName());
        }
//        IndexDto idto = new IndexDto(bst, bs);
        PrintWriter out = response.getWriter();
        ObjectMapper om = new ObjectMapper();
//        out.print(om.writeValueAsString(idto));
        out.print(om.writeValueAsString(bs));

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}
